package com.example.jvm.chapter03;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ThreadLocalMapExample {
    private static final Logger log = LoggerFactory.getLogger(ThreadLocalMapExample.class);

    private ThreadLocal<Integer> local = new ThreadLocal<>();

    public static void main(String[] args) {
        new Thread(() -> {
//            test();
//            System.gc();
            ThreadLocalMapExample example = new ThreadLocalMapExample();
            ThreadLocal<Integer> local1 = new ThreadLocal<>();
//            local1.set(2);
            example.test();
            example.local = null;
            System.gc();
            Thread thread = Thread.currentThread();
            local1.set(10000);
            ThreadLocal<Integer> local2 = new ThreadLocal<>();
            local2.set(100001);
            local2.remove();
//            new Thread().start();
//            try {
//                TimeUnit.SECONDS.sleep(20);
//            } catch (InterruptedException e) {
//                log.error("error", e);
//            }
//            local.set(101);
//            System.out.println(local);
//            System.out.println();
        }).start();
    }

    public void test() {
        local.set(100);
    }
}
